home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2001 December / pcwk12201b.iso / Wersje pelne i specjalne / Ghostscript 7.0 / gs700w32.exe / gs7.00 / lib / pdf2dsc.ps < prev    next >
Text File  |  2000-12-28  |  5KB  |  167 lines

  1. %    Copyright (C) 1994, 1995, 1996, 1997, 1998 Aladdin Enterprises.  All rights reserved.
  2. % This file is part of AFPL Ghostscript.
  3. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  4. % distributor accepts any responsibility for the consequences of using it, or
  5. % for whether it serves any particular purpose or works at all, unless he or
  6. % she says so in writing.  Refer to the Aladdin Free Public License (the
  7. % "License") for full details.
  8. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  9. % in a plain ASCII text file named PUBLIC.  The License grants you the right
  10. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  11. % conditions described in the License.  Among other things, the License
  12. % requires that the copyright notice and this notice be preserved on all
  13. % copies.
  14.  
  15. % $Id: pdf2dsc.ps,v 1.3 2000/12/29 05:03:49 alexcher Exp $
  16. % pdf2dsc.ps
  17. % read pdf file and produce DSC "index" file.
  18. %
  19. % Input  file is named PDFname
  20. % Output file is named DSCname
  21. %
  22. % Run using:
  23. %  gs -dNODISPLAY -sPDFname=pdffilename -sDSCname=tempfilename pdf2dsc.ps
  24. % Then display the PDF file with
  25. %  gs tempfilename
  26. %
  27. % Modified by Geoff Keating <geoffk@ozemail.com.au> 21/12/98:
  28. %    Add DocumentMedia, PageMedia comments
  29. %    Use inherited BoundingBox and Orientation
  30. %    Reformat, add new macro 'puts', generally clean up
  31. % Modified by Johannes Plass <plass@dipmza.physik.uni-mainz.de> 1996-11-05:
  32. %    Adds BoundingBox and Orientation if available.
  33. % Modified by rjl/lpd 9/19/96
  34. %    Updates for compatibility with modified pdf_*.ps code for handling
  35. %      page ranges (i.e., partial files) better.
  36. % Modified by Geoff Keating <Geoff.Keating@anu.edu.au> 7/3/96:
  37. %    include Title and CreationDate DSC comments (these are displayed by
  38. %      Ghostview);
  39. %    reduce the size of typical output files by a factor of about 3.
  40. % Modified by L. Peter Deutsch 3/18/96:
  41. %    Removes unnecessary and error-prone code duplicated from pdf_main.ps
  42. % Modified by L. Peter Deutsch for GS 3.33
  43. % Originally by Russell Lang  1995-04-26
  44.  
  45. /DSCfile DSCname (w) file def
  46. systemdict /.setsafe known { .setsafe } if
  47.  
  48. /puts { DSCfile exch writestring } bind def
  49. /DSCstring 255 string def
  50. /MediaTypes 10 dict def
  51.  
  52. % (str1) (str2)  concatstr  (str1str2)
  53. /concatstr {
  54.   2 copy length exch length add string
  55.   dup dup 5 2 roll copy length
  56. % stack: newstring newstring str2 str1-length
  57.   exch putinterval
  58. } bind def
  59.  
  60.    GS_PDF_ProcSet begin
  61.    pdfdict begin
  62.    PDFname (r) file
  63.    pdfopen begin
  64.    /FirstPage where { pop } { /FirstPage 1 def } ifelse
  65.    /LastPage where { pop } { /LastPage pdfpagecount def } ifelse
  66.  
  67. % scan through for media sizes, keep them in the dictionary
  68.    FirstPage 1 LastPage {
  69.       pdfgetpage /MediaBox pget pop   % MediaBox is a required attribute
  70.       aload pop 
  71.       3 -1 roll sub 3 1 roll exch sub exch
  72.       2 array astore 
  73.       aload 3 1 roll 10 string cvs exch 10 string cvs
  74.       (x) exch concatstr concatstr cvn
  75.       MediaTypes 3 1 roll exch put
  76.    } for
  77.  
  78. % write header and prolog
  79.    (%!PS-Adobe-3.0\n) puts
  80.    Trailer /Info knownoget
  81.     {
  82.       dup /Title knownoget
  83.        {
  84.          (%%Title: ) puts
  85.          DSCfile exch write==
  86.        }
  87.       if
  88.       /CreationDate knownoget
  89.        {
  90.          (%%CreationDate: ) puts
  91.          DSCfile exch write==
  92.        }
  93.       if
  94.     }
  95.    if
  96.    % This is really supposed to be sorted by frequency of usage...
  97.    (%%DocumentMedia: )
  98.    MediaTypes { 
  99.       exch pop
  100.       1 index puts
  101.       (y) puts dup 1 get DSCstring cvs puts
  102.       (x) puts dup 0 get DSCstring cvs puts 
  103.       ( ) puts dup 0 get DSCstring cvs puts
  104.       ( ) puts 1 get DSCstring cvs puts 
  105.       ( 70 white ()\n) puts
  106.       pop (%%+ )
  107.    } forall
  108.    pop
  109.  
  110.    (%%Pages: ) puts
  111.    LastPage FirstPage sub 1 add DSCstring cvs puts
  112.    (\n%%EndComments\n) puts
  113.    (%%BeginProlog\n) puts
  114.    (/Page null def\n/Page# 0 def\n/PDFSave null def\n) puts
  115.    (/DSCPageCount 0 def\n) puts
  116.    (/DoPDFPage {dup /Page# exch store pdfgetpage pdfshowpage } def\n) puts
  117.    (GS_PDF_ProcSet begin\npdfdict begin\n) puts
  118.    (%%EndProlog\n) puts
  119.    (%%BeginSetup\n) puts
  120.    DSCfile PDFname write==only
  121.    ( \(r\) file pdfopen begin\n) puts
  122.    (%%EndSetup\n) puts
  123.    % process each page
  124.    FirstPage 1 LastPage {
  125.        (%%Page: ) puts
  126.        dup DSCstring cvs puts
  127.        ( ) puts
  128.        dup DSCstring cvs puts
  129.        (\n) puts
  130.  
  131.        dup pdfgetpage
  132.        dup /MediaBox pget pop
  133.          (%%PageMedia: y) puts
  134.      aload pop 3 -1 roll sub DSCstring cvs puts
  135.      (x) puts exch sub DSCstring cvs puts
  136.      (\n) puts
  137.        dup /CropBox pget {
  138.          (%%PageBoundingBox: ) puts
  139.          {DSCfile exch write=only ( ) puts} forall
  140.          (\n) puts
  141.        } if
  142.        /Rotate pget {
  143.          (%%PageOrientation: ) puts
  144.          90 div cvi 4 mod dup 0 lt {4 add} if
  145.          [(Portrait) (Landscape) (UpsideDown) (Seascape)] exch get puts
  146.          (\n) puts
  147.        } if
  148.  
  149.        DSCfile exch DSCstring cvs writestring
  150.        ( DoPDFPage\n) puts
  151.     } for
  152.    currentdict pdfclose
  153.    end
  154.    end
  155.    end
  156. % write trailer
  157. (%%Trailer\n) puts
  158. (currentdict pdfclose\nend\nend\nend\n) puts
  159. (%%EOF\n) puts
  160. % close output file and exit
  161. DSCfile closefile
  162. quit
  163. % end of pdf2dsc.ps
  164.